<?php
/**
	Classes: address (myDbTb :: myClass)

	IT manages the address data to make database operations
*/
class address extends myDbTb{
	public $id;
	public $firstname;
	public $lastname;
	public $street;
	public $country_id=DEFAULT_COUNTRY_ID;
	public $zone_id;
	public $postcode;
	public $city;
	public $user_id;
	public $zone; // The zone object
	public $country; // The country object

	/*
	 * It loads address data from DB
	 * It returns 0 if the data has not been loaded.
	 */
	function db_load() {
		$sql = "SELECT a.* FROM " .
			TABLE_ADDRESS_BOOK . " a " .
			" where a.id = '".$this->id."'";

		return $this->sql_request($sql);
	}

	/**
	 * It updates address data to DB.
	 * It returns 0 if the data has not been updated.
	 */
	function db_update() {
		$sql = "UPDATE "
				. TABLE_ADDRESS_BOOK . " a "
				. " SET"
				. " a.firstname='" . $this->firstname . "'"
				. " , a.lastname='" . $this->lastname . "'"
				. " , a.street='" . $this->street . "'"
				. " , a.postcode='" . $this->postcode . "'"
				. " , a.city='" . $this->city . "'"
				. " , a.zone_id='" . $this->zone_id . "'"
				. " , a.country_id='" . $this->country_id . "'"
			. " WHERE"
				. " a.id ='".$this->id."'";

		return $this->sql_request($sql);
	}
	/**
	 * It inserts address data to database and sets address->id to the inserted id value
	 * It returns 0 if the data has not been inserted.
	 */
	function db_insert() {
		$sql = "INSERT INTO "
				. TABLE_ADDRESS_BOOK
			. " ("
				. " user_id"
				. " , firstname"
				. " , lastname"
				. " , street"
				. " , postcode"
				. " , city"
				. " , zone_id"
				. " , country_id"
			. " ) VALUES ("
				. $this->user_id
				. " , '" . $this->firstname ."'"
				. " , '" . $this->lastname ."'"
				. " , '" . $this->street ."'"
				. " , '" . $this->postcode ."'"
				. " , '" . $this->city ."'"
				. " , " . $this->zone_id
				. " , " . $this->country_id
			. " )";

		return $this->sql_request($sql);
	}
}
?>
